package com.yenlien.traceyun.business.controller.from;

import com.yenlien.traceyun.business.entity.BaseSoil;
import com.yenlien.traceyun.business.entity.Warehouse;
import com.yenlien.traceyun.business.entity.WarehousePart;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.*;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-12-21
 * @description:
 **/
public class WarehouseForm extends BaseSoil {

    /**
     * 地块id
     */
    private String massifId;

    private String warehouseId;

    private String warehousePartsName;

    private String warehouseParts;

    private String soilImg;                //地块全景图

    public BaseSoil getBaseSoil() {
        BaseSoil baseSoil = new BaseSoil();
        BeanUtils.copyProperties(this, baseSoil);
        return baseSoil;
    }

    public Warehouse getWarehouse() {
        Warehouse warehouse = new Warehouse();
        warehouse.setId(warehouseId);
        warehouse.setName(getName());
        warehouse.setUid(getPrincipalId());
        warehouse.setUname(getPrincipalName());
        return warehouse;
    }

    public List<WarehousePart> getWarehouseParts() {
        List<WarehousePart> parts = null;
        if (!StringUtils.isEmpty(warehouseParts)) {
            String[] partNames = warehouseParts.split(",");

            if (partNames != null && partNames.length > 0) {
                Set<String> sets = new HashSet<>(Arrays.asList(partNames));
                parts = new ArrayList<>();
                for (String item : sets) {
                    WarehousePart part = new WarehousePart();
                    part.setName(item);
                    parts.add(part);
                }
            }
        }
        return parts;
    }

    public String getWarehousePartsName() {
        return warehousePartsName;
    }

    public void setWarehousePartsName(String warehousePartsName) {
        this.warehousePartsName = warehousePartsName;
    }

    public String getWarehouseId() {
        return warehouseId;
    }

    public void setWarehouseId(String warehouseId) {
        this.warehouseId = warehouseId;
    }

    public void setWarehouseParts(String warehouseParts) {
        this.warehouseParts = warehouseParts;
    }

    @Override
    public String getSoilImg() {
        return soilImg;
    }

    @Override
    public void setSoilImg(String soilImg) {
        this.soilImg = soilImg;
    }

    public String getMassifId() {
        return massifId;
    }

    public void setMassifId(String massifId) {
        this.massifId = massifId;
    }

    @Override
    public String toString() {
        return "WarehouseForm{" +
                "massifId='" + massifId + '\'' +
                ", warehouseId='" + warehouseId + '\'' +
                ", warehousePartsName='" + warehousePartsName + '\'' +
                ", warehouseParts='" + warehouseParts + '\'' +
                ", soilImg='" + soilImg + '\'' +
                '}';
    }
}
